---
title: |
  | Analysis: Did the GDPR policy have an impact
  | attitudes towards data sharing/privacy?
author: 'Paul C. Bauer, Frederic Gerdon, Florian Keusch, Frauke Kreuter, David Vannette'
date:  |
  | `r gsub("^0", "", format(Sys.time(), "%d %B, %Y"))`
output:
  html_document:
    toc: true
    toc_depth: 2
---

<style>
/* Whole document: */
body{
  font-family: Georgia;
  font-size: 11pt;
  text-align: justify;
}
pre {
  white-space: pre !important;
  overflow-y: scroll !important;
}
</style>

```{r setup, include=FALSE}
knitr::opts_chunk$set(cache = FALSE)

# Packages
library(haven)
library(plotly)
library(dplyr)
library(stargazer)
library(readr)
library(stringr)
library(xtable)
library(kableExtra)
library(knitr)
library(tidyr)
library(broom)
library(gridExtra)
library(gtrendsR)
library(reshape2)
library(lubridate)
library(plm)
library(gridExtra)
library(grid)
library(purrr)
library(markdown)
library(stringi)
library(ggcorrplot)
library(ggpubr)

g_legend<-function(a.gplot){
  tmp <- ggplot_gtable(ggplot_build(a.gplot))
  leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
  legend <- tmp$grobs[[leg]]
  return(legend)}

```



# Load datasets

```{r load-data}
load("./data.RData")
```












# Main section


## Figure 1: Field periods, google searches & events

```{r figure1-field-period, echo=TRUE}


# Words to search for
search.words <- c("GDPR", "DSGVO")

# Download google trends
google.trends <- gtrends(search.words, gprop = "web", time = "2018-03-01 2018-11-16", geo = "DE")[[1]]
google.trends <- dcast(google.trends, date ~ keyword + geo, value.var = "hits")

google.trends <- data.frame(lapply(google.trends, function(x) {
  gsub("<1", "0", x)
}))

# Rename variables
names(google.trends) <- gsub("-", "_", names(google.trends))
names(google.trends) <- gsub(" ", "_", names(google.trends))

# Convert date variable
google.trends$date <- as.Date(google.trends$date, "%Y-%m-%d")

# Mutate factor to numeric and reorder
google.trends <- google.trends %>%
  mutate_if(is.factor, as.character) %>%
  mutate_if(is.character, as.numeric) %>%
  select(
    "date",
    "DSGVO_DE",
    "GDPR_DE"
  )

# Aggregate up to weeks
# google.trends <- google.trends %>% group_by(week=floor_date(date, "week")) %>% summarize_all(mean)


png("./figure1.png", width = 8, height = 4, units = "in", res = 600)
par(oma = c(0, 0, 0, 0), mar = c(4, 4, 1, 1))

plot(1,
  type = "n",
  xlab = "Month (2018)",
  ylab = "Searches (100 = max. interest in time period/territory)",
  ylim = c(0, 100),
  xlim = c(min(google.trends$date), max(google.trends$date)),
  xaxt = "n",
  cex.axis = 0.8,
  cex.lab = 0.8
)
# Polygons for field periods
# 16th - 23rd of April (Survey & Period 1), 24th of July until 2nd of August (Survey & Period 2) and 29th of October until 7th of November
# Period 1
xx <- c("2018-04-16", "2018-04-23", "2018-04-23", "2018-04-16")
xx <- as.Date(xx, "%Y-%m-%d")
yy <- c(0, 0, 100, 100)
# When density=0, col refers to the line colour
polygon(xx, yy, density = 100, col = "gray")

# Period 2
xx <- c("2018-07-24", "2018-08-02", "2018-08-02", "2018-07-24")
xx <- as.Date(xx, "%Y-%m-%d")
yy <- c(0, 0, 100, 100)
# When density=0, col refers to the line colour
polygon(xx, yy, density = 100, col = "gray")

# Period 3
xx <- c("2018-10-29", "2018-11-07", "2018-11-07", "2018-10-29")
xx <- as.Date(xx, "%Y-%m-%d")
yy <- c(0, 0, 100, 100)
# When density=0, col refers to the line colour
polygon(xx, yy, density = 100, col = "gray")

# Line for 25th of May: Implementation
abline(
  v = as.Date("2018-05-25", "%Y-%m-%d"),
  col = "red",
  lty = "dashed",
  lwd = 2
)

# # Line for 22th of May: Zuckerberg
# abline(
#   v = as.Date("2018-05-22", "%Y-%m-%d"),
#   col = "black",
#   lty = "dotted",
#   lwd = 1
# )

# Add axis - months (tickmark on the first)
axis(1, unique(floor_date(google.trends$date, "month")),
  format(unique(floor_date(google.trends$date, "month")), "%b-%d"),
  cex.axis = .6
)
# Add search words
lines(google.trends$date,
  google.trends$DSGVO_DE,
  col = "black",
  lty = "solid"
)
lines(google.trends$date,
  google.trends$GDPR_DE,
  col = "darkgreen",
  lty = "longdash"
)

# Add a legend
legend.names <- gsub("_DE", "", names(google.trends)[-1])
legend.names <- gsub("\\.", " ", legend.names)
legend(as.Date("2018-8-10", "%Y-%m-%d"),
  100,
  legend = c(
    legend.names,
    "",
    "Field periods (Wave 1, 2 and 3)",
    "Policy implementation (25 of May)"),
  col = c("black", "darkgreen", NA, "gray", "red"),
  lty = c("solid", "longdash", NA, NA, "dashed"),
  lwd = c(1, 1, NA, NA, 2),
  pch = c(NA, NA, NA, 15, NA),
  cex = 0.6,
  title = "Search terms, field periods & events:"
)

dev.off()
```

![](./figure1.png)


<br><br><br>

## Figure 2: Experimental setup

-- Not generated in R, See Paper --

<br><br><br>

## Figure 3: GDPR Awareness across waves


```{r}
# Code below produces the in-text values.

# WAVE 1
x <- data %>% 
  filter(wave == "Wave 1")

# OLD GDPR know variable
prop.table(table(x$gdpr.know))
table(x$gdpr.know, x$gdpr.know.num.old)
table(x$gdpr.know.new, x$gdpr.know.num)
table(x$gdpr.know.num.old, x$gdpr.know.num)

# NEW GDPR know variable
prop.table(table(x$gdpr.know.new))
round(prop.table(table(x$gdpr.know.new)), 2) # Value of recoded GDPR aware var (1 = Yes)


# WAVE 2

# WAVE 1
x <- data %>% 
  filter(wave == "Wave 2")

# OLD GDPR know variable
prop.table(table(x$gdpr.know))
table(x$gdpr.know, x$gdpr.know.num.old)
table(x$gdpr.know.new, x$gdpr.know.num)
table(x$gdpr.know.num.old, x$gdpr.know.num)

# NEW GDPR know variable
prop.table(table(x$gdpr.know.new))
round(prop.table(table(x$gdpr.know.new)), 2) # Value of recoded GDPR aware var (1 = Yes)

```



```{r figure4-gdpr-means, message=FALSE, warning=FALSE, paged.print=FALSE}
data.expand <- data %>% expand(pid, wave.num)
data.expand <- data %>% right_join(data.expand) %>% arrange(pid, wave.num)
participation <- data.expand %>% group_by(pid) %>% summarise(participation = paste(wave, collapse = "_"))
data.expand <- left_join(data.expand, participation, by = "pid")

# Means for full wave samples
means.sample.waves <- data.expand %>%
  group_by(wave) %>%
  filter(participation != "NA_Wave 2_Wave 3", participation != "Wave 1_NA_Wave 3") %>%
  summarize(
    gdpr.know.num.mean = mean(gdpr.know.num, na.rm = TRUE),
    gdpr.know.num.sd = sd(gdpr.know.num, na.rm = TRUE),
    n = n(),
    n_wo_NA = sum(!is.na(gdpr.know.num)),
    se = gdpr.know.num.sd/sqrt(n_wo_NA),
    ci_95 = qnorm(1 - 0.05/2)*se,
    ci_90 = qnorm(1 - 0.1/2)*se) %>%
  na.omit() %>%
  mutate(participation = wave)

# Means for sample subgroups
means.sample.subgroups <- data.expand %>%
  group_by(participation, wave) %>%
  filter(
    participation != "NA_Wave 2_Wave 3",
    participation != "Wave 1_NA_Wave 3"
  ) %>%
  summarize(
    gdpr.know.num.mean = mean(gdpr.know.num, na.rm = TRUE),
    gdpr.know.num.sd = sd(gdpr.know.num, na.rm = TRUE),
    n = n(),
    n_wo_NA = sum(!is.na(gdpr.know.num)),
    se = gdpr.know.num.sd/sqrt(n_wo_NA),
    ci_95 = qnorm(1 - 0.05/2)*se,
    ci_90 = qnorm(1 - 0.1/2)*se) %>%
  na.omit()

means <- bind_rows(means.sample.waves, means.sample.subgroups)
# Delete groups only W2/W3 (N = 3) and only W1/W3 (N = 2)
means <- means %>% filter(n > 10)

# Add lables for graph
means <- means %>%
  mutate(label = recode(participation,
    "Wave 1" = "Full Sample",
    "Wave 2" = "Full Sample",
    "Wave 3" = "Full Sample",
    "NA_NA_Wave 3" = "Only W3",
    "NA_Wave 2_NA" = "Only W2",
    "Wave 1_NA_NA" = "Only W1",
    "Wave 1_Wave 2_NA" = "W1 and W2",
    "Wave 1_Wave 2_Wave 3" = "W1, W2 and W3"
  )) %>% mutate(gdpr.know.num.mean = gdpr.know.num.mean*100,
                ci_95 = ci_95 * 100,
                ci_90 = ci_90 * 100)



# Get per Wave N for x-axis labels
# EXCLUDES: 5 Respondents who participated only in W2 and W3 (N = 3) and only in W1 and W3 (N = 2)
means %>%
  group_by(wave) %>%
  filter(
    participation != "Wave 1",
    participation != "Wave 2",
    participation != "Wave 3"
  ) %>%
  summarize(sum(n, na.rm = T))

# INCLUDES: 5 Repondents that participated only in W2 and W3 (N = 3) and only in W1 and W3 (N = 2) and only in W3 ()
data %>% group_by(wave) %>% summarize(n = n())
# 2095 - 2093 = 2
# 2046 - 2043 = 3
# 2117 - 2112 = 5 


pd <- position_dodge(0.6)
ggplot(means, aes(x = wave, y = gdpr.know.num.mean, color = factor(label), group = factor(label))) +
    geom_errorbar(aes(ymin=gdpr.know.num.mean - ci_90, 
                    ymax=gdpr.know.num.mean + ci_90,
                    color = factor(label)), 
                colour="black",
                size = 1,
                width=.0, 
                position=pd) + 
      geom_errorbar(aes(ymin=gdpr.know.num.mean - ci_95, 
                    ymax=gdpr.know.num.mean + ci_95,
                    color = factor(label)), 
                colour="black",
                size = 0.4,
                width=.1, 
                position=pd) +
  geom_point(
    size = 3,
    position=pd
  ) +

  scale_shape(solid = FALSE) +
  ylim(0, 100) +
  ylab("% GDPR Awareness") +
  scale_x_discrete(labels = c(
    "Wave 1 (N = 2093)\nApr 16 - 23, 2018",
    "Wave 2 (N = 2043)\nJul 24 - Aug 02, 2018",
    "Wave 3 (N = 2112)\nOct 29 - Nov 07, 2018"
  )) +
  theme_light() +
  theme(axis.title.x = element_blank()) + scale_color_manual(
    values = c("black", "#e41a1c", "#377eb8", "#4daf4a", "#984ea3", "#ff7f00"),
    name = "Participation",
    breaks = levels(factor(means$label)),
    labels = c(
      "Full Sample",
      "Only W1 (N = 532)",
      "Only W2 (N = 482)",
      "Only W3 (N = 843)",
      "W1 and W2 (N = 292)",
      "W1, W2 and W3 (N = 1269)"
    )
  )
ggsave("./figure3.png", width = 7, height = 4)

# dput(levels(factor(means$label)))
```




<br><br><br>



## Table A5/Figure 4: LM Cross-sectional data from Wave 1

```{r tableA5, results="asis"}
treatment <- "gdpr.know.new"
controls <- c("female", "age.cat.fac", "school.educ.num4.fact", "privacy.worry.numeric", "account.facebook.fac", "account.google.fac", "device.smartphone.dummy", "device.handy.dummy", "device.desktop.dummy", "device.tablet.dummy", "device.ereader.dummy", "trust.generalized")


as.formula(paste("trust.google", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ "))

tab1.trust.google.w1 <- lm(trust.google ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.facebook.w1 <- lm(trust.facebook ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.fedoffstats.w1 <- lm(trust.fedoffstats ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.researchers.w1 <- lm(trust.researchers ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)

tab1.trust.google.w1.full <- lm(as.formula(paste("trust.google", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.facebook.w1.full <- lm(as.formula(paste("trust.facebook", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.fedoffstats.w1.full <- lm(as.formula(paste("trust.fedoffstats", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.researchers.w1.full <- lm( as.formula(paste("trust.researchers", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

stargazer(tab1.trust.google.w1, tab1.trust.google.w1.full,
  tab1.trust.facebook.w1, tab1.trust.facebook.w1.full,
  tab1.trust.fedoffstats.w1, tab1.trust.fedoffstats.w1.full,
  tab1.trust.researchers.w1, tab1.trust.researchers.w1.full,
  type = "html",
  dep.var.labels.include = FALSE,
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  # model.names = paste("(M", 1:8,")", sep=""),
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:pooled",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2),
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents in Wave 1."),
  header = FALSE,
  no.space = TRUE,
  font.size = "tiny",
  covariate.labels = c(
    "GDPR Awareness (No = 0, Yes = 1)",
    "Female",
    "Age: 30-49 (ref.:<30)",
    "Age: >=50 (ref.:<30)",
    "Education (ref. Hauptschule): Mittlere Reife",
    "Education (ref. Hauptschule): Fachabitur",
    "Education (ref. Hauptschule): Abitur",
    "Privacy concern",
    "Account Facebook: No, but before (ref.: Never)",
    "Account Facebook: Yes (ref.: Never)",
    "Account Google: No, but before (ref.: Never)",
    "Account Google: Yes (ref.: Never)",
    "Device: Smartphone",
    "Device: Cell phone (no smartphone)",
    "Device: Desktop/Laptop",
    "Device: Tablet",
    "Device: eReader",
    "Generalized trust"
  ),
  out = "./tableA5.html"
)
```


<br><br><br>


```{r figure6}

models <- c("tab1.trust.facebook.w1", 
"tab1.trust.facebook.w1.full",
"tab1.trust.fedoffstats.w1",
"tab1.trust.fedoffstats.w1.full",
"tab1.trust.google.w1",
"tab1.trust.google.w1.full",
"tab1.trust.researchers.w1",
"tab1.trust.researchers.w1.full")

allmodels <- NULL
for(i in 1:length(models)){
  fit_i <- get(models[i])
  name_i <- as.character(formula(fit_i))[2]

model_i <- tidy(fit_i) %>% 
     rename("Variable" = "term") %>% 
       rename("Coefficient" = "estimate") %>% 
       rename("SE" = "std.error") %>%
      # mutate(Model = sub('.*\\.', '', name_i)) %>%
      mutate(Outcome = name_i) %>%
  filter(Variable!="(Intercept)") %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(Variable))) %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(levels(Variable))))

if(str_detect(models[i], "full")){model_i$Model <- "With Controls"}else{model_i$Model <- "No Controls"}

allmodels <- data.frame(rbind(allmodels, model_i)) 
    
}  


allmodels$Variable <- recode(allmodels$Variable,
                             "gdpr.know.new" = "GDPR Awareness (No = 0, Yes = 1)",
"female" = "Female", 
"age.cat.fac30to50" = "Age: 30-49 (ref.:<30)",
"age.cat.facabove50" = "Age: >=50 (ref.:<30)", 
"school.educ.num4.factMittlere Reife" = "Education (ref. Hauptschule): Mittlere Reife", 
"school.educ.num4.factFachhochschulreife" = "Education (ref. Hauptschule): Fachabitur", 
"school.educ.num4.factAbitur" = "Education (ref. Hauptschule): Abitur", 
"privacy.worry.numeric" = "Privacy concern", 
"account.facebook.facNo, but before" = "Account Facebook: No, but before (ref.: Never)", 
"account.facebook.facYes" = "Account Facebook: Yes (ref.: Never)", 
"account.google.facNo, but before" = "Account Google: No, but before (ref.: Never)", 
"account.google.facYes" = "Account Google: Yes (ref.: Never)", 
"device.smartphone.dummy" = "Device: Smartphone", 
"device.handy.dummy" = "Device: Cell phone (no smartphone)", 
"device.desktop.dummy" = "Device: Desktop/Laptop", 
"device.tablet.dummy" = "Device: Tablet", 
"device.ereader.dummy" = "Device: eReader", 
"trust.generalized" = "Generalized trust")




allmodels$Outcome <- gsub("\\.", " ", allmodels$Outcome)
allmodels$Outcome <- str_to_title(allmodels$Outcome) 

allmodels$Model[allmodels$Model=="withcontrols"] <- "With Controls"
allmodels$Model[allmodels$Model=="nocontrols"] <- "No Controls"
                             
allmodels <- allmodels %>% filter(!str_detect(Variable, "Account"))
allmodels <- allmodels %>% filter(!str_detect(Variable, "Device"))
allmodels <- allmodels %>% filter(str_detect(Variable, "GDPR|Privacy concern|Generalized trust"))

allmodels$Variable <- droplevels(allmodels$Variable)

levels(allmodels$Variable)[2] <- "Privacy concern (0-3)"
levels(allmodels$Variable)[3] <- "Generalized trust (0-10)"

#allmodels$Variable <- str_wrap(allmodels$Variable, width = 20)

# Specify the width of your confidence intervals
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2)  # 95% multiplier

allmodels$Coefficient_labels <- as.numeric(factor(paste(allmodels$Outcome, allmodels$Model, sep="")))
allmodels$Coefficient_labels <- paste(round(allmodels$Coefficient, 2), " (M", allmodels$Coefficient_labels, ")",sep="")
allmodels$Outcome <- gsub("Trust Researchers", "Trust University Researchers", allmodels$Outcome)



# CHANGE ORDER
  allmodels$Outcome <- factor(allmodels$Outcome, 
                              levels = c("Trust Facebook", "Trust Google", "Trust Fedoffstats", "Trust University Researchers"),
                              ordered = TRUE)
  allmodels$order1 <- allmodels$Variable
  allmodels$order1 <- recode(allmodels$order1,
    "GDPR Awareness (0 = No Change, 1 = Positive Change)" = "1",
    "Privacy concern (0-3)" = "2",
    "Generalized trust (0-10)" = "3"
  )
  allmodels$order2 <- allmodels$Outcome
  allmodels$order2<- recode(allmodels$order2,
    "Trust Facebook" = "1",
    "Trust Google" = "2",
    "Trust Fedoffstats" = "3",
    "Trust University Researchers" = "4"
  )
  allmodels <- allmodels %>% arrange(order1, order2)
  allmodels$plot_order_index <- 1:nrow(allmodels)






# Plot
ggplot(allmodels, aes(x = Variable, y = Coefficient, group = plot_order_index)) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1,
                     shape = Model,
                     colour = Outcome),
                            lwd = 1, position = position_dodge2(reverse = TRUE, width = 0.8)) + 
  geom_pointrange(aes(x = Variable, 
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2,
                      ymax = Coefficient + SE*interval2,
                      shape = Model,
                      colour = Outcome),
                  lwd = 1/2,
                  position = position_dodge2(reverse = TRUE, width = 0.8),
                  fill = "WHITE") +
  geom_text(aes(x = Variable,
                y = Coefficient + SE*interval2+0.25,
                label = Coefficient_labels,
                     shape = Model,
                     colour = Outcome),
            position = position_dodge2(reverse = TRUE, width = 0.8),
            size = 3) +
  coord_flip() + 
  theme_bw() +
    labs(shape = "Model Type") +
  scale_x_discrete(limits = rev(levels(allmodels$Variable)), 
                   labels = str_wrap(rev(levels(allmodels$Variable)), width = 17)) + 
  scale_colour_discrete(labels = function(x) str_wrap(x, width = 17)) +
  labs(colour = "Outcome (Scale: 0 - 10)") +
  theme_light()+
  ylim(NA, 1.55)



ggsave("./figure4.png", width = 7, height = 4)
```


## Table A6/Figure 5: Diff-n-diff

Generate data. 

```{r generate-data-for-lm-did, echo=TRUE}
# Outcome is the change between Wave 1 and Wave 2. Treatment the same (Change can only be 0 or 1). For control variables we replace values in Wave 2 with the lead value, i.e. value of Wave 1 of the respective control variable. Finally, we subset on Wave 2.

# Generate new dataset
  data.did <- data.w1w2
data.did <- data.did %>% arrange(pid, wave) %>%
  group_by(pid) %>%
  mutate(# fill covariate values of Wave 2 with values of Wave 1
     female = dplyr::lag(female, n = 1, default = NA),
     age.cat.fac = dplyr::lag(age.cat.fac, n = 1, default = NA),
     school.educ.num4.fact = dplyr::lag(school.educ.num4.fact, n = 1, default = NA),
     privacy.worry.numeric = dplyr::lag(privacy.worry.numeric, n = 1, default = NA),
     account.facebook.fac = dplyr::lag(account.facebook.fac, n = 1, default = NA),
     account.google.fac = dplyr::lag(account.google.fac, n = 1, default = NA),
     device.smartphone.dummy = dplyr::lag(device.smartphone.dummy, n = 1, default = NA),
     device.handy.dummy = dplyr::lag(device.handy.dummy, n = 1, default = NA),
     device.desktop.dummy = dplyr::lag(device.desktop.dummy, n = 1, default = NA),
     device.tablet.dummy = dplyr::lag(device.tablet.dummy, n = 1, default = NA),
     device.ereader.dummy = dplyr::lag(device.ereader.dummy, n = 1, default = NA),
     trust.google = dplyr::lag(trust.google, n = 1, default = NA),
     trust.facebook = dplyr::lag(trust.facebook, n = 1, default = NA),
     trust.fedoffstats = dplyr::lag(trust.fedoffstats, n = 1, default = NA),
     trust.researchers = dplyr::lag(trust.researchers, n = 1, default = NA),
     number.devices = dplyr::lag(number.devices, n = 1, default = NA),
     number.accounts = dplyr::lag(number.accounts, n = 1, default = NA),
     abitur = dplyr::lag(abitur, n = 1, default = NA),
     trust.generalized = dplyr::lag(trust.generalized, n = 1, default = NA)) %>% filter(wave == "Wave 2")

```

```{r tableA6, echo=TRUE, results="asis"}
# Lm models for comparison of intercepts
outcomes <- c("trust.google.diff", "trust.facebook.diff", "trust.fedoffstats.diff", "trust.researchers.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did)
         )

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel)."),
  header = FALSE,
  no.space = TRUE,
  covariate.labels = c(
    "GDPR Awareness (0 = No Change, 1 = Positive Change)",
    "Female",
    "Age: 30-49 (ref.:<30)",
    "Age: >=50 (ref.:<30)",
    "Education (ref. Hauptschule): Mittlere Reife",
    "Education (ref. Hauptschule): Fachabitur",
    "Education (ref. Hauptschule): Abitur",
    "Privacy concern",
    "Account Facebook: No, but before (ref.: Never)",
    "Account Facebook: Yes (ref.: Never)",
    "Account Google: No, but before (ref.: Never)",
    "Account Google: Yes (ref.: Never)",
    "Device: Smartphone",
    "Device: Cell phone (no smartphone)",
    "Device: Desktop/Laptop",
    "Device: Tablet",
    "Device: eReader",
    "Generalized trust"),
  font.size = "tiny",
  out = "./tableA6.html"
)
```




```{r figure7}

allmodels <- NULL
for(i in 1:length(model.list)){
  name_i <- names(model.list)[i]

model_i <- tidy(model.list[[i]]) %>% 
     rename("Variable" = "term") %>% 
       rename("Coefficient" = "estimate") %>% 
       rename("SE" = "std.error") %>%
      mutate(Model = sub('.*\\.', '', name_i)) %>%
      mutate(Outcome = gsub("fit.lm.|.diff.withcontrols|.diff.nocontrols","", name_i)) %>%
  filter(Variable!="(Intercept)") %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(Variable))) %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(levels(Variable))))

allmodels <- data.frame(rbind(allmodels, model_i)) 
    
}  


allmodels$Variable <- recode(allmodels$Variable,
                             "gdpr.know.num.diff" = "GDPR Awareness (0 = No Change, 1 = Positive Change)",
"female" = "Female", 
"age.cat.fac30to50" = "Age: 30-49 (ref.:<30)",
"age.cat.facabove50" = "Age: >=50 (ref.:<30)", 
"school.educ.num4.factMittlere Reife" = "Education (ref. Hauptschule): Mittlere Reife", 
"school.educ.num4.factFachhochschulreife" = "Education (ref. Hauptschule): Fachabitur", 
"school.educ.num4.factAbitur" = "Education (ref. Hauptschule): Abitur", 
"privacy.worry.numeric" = "Privacy concern", 
"account.facebook.facNo, but before" = "Account Facebook: No, but before (ref.: Never)", 
"account.facebook.facYes" = "Account Facebook: Yes (ref.: Never)", 
"account.google.facNo, but before" = "Account Google: No, but before (ref.: Never)", 
"account.google.facYes" = "Account Google: Yes (ref.: Never)", 
"device.smartphone.dummy" = "Device: Smartphone", 
"device.handy.dummy" = "Device: Cell phone (no smartphone)", 
"device.desktop.dummy" = "Device: Desktop/Laptop", 
"device.tablet.dummy" = "Device: Tablet", 
"device.ereader.dummy" = "Device: eReader", 
"trust.generalized" = "Generalized trust")




allmodels$Outcome <- gsub("\\.", " ", allmodels$Outcome)
allmodels$Outcome <- str_to_title(allmodels$Outcome) 

allmodels$Model[allmodels$Model=="withcontrols"] <- "With Controls"
allmodels$Model[allmodels$Model=="nocontrols"] <- "No Controls"
                             
allmodels <- allmodels %>% filter(!str_detect(Variable, "Account"))
allmodels <- allmodels %>% filter(!str_detect(Variable, "Device"))

allmodels <- allmodels %>% filter(str_detect(Variable, "GDPR|Privacy concern|Generalized trust"))

allmodels$Variable <- droplevels(allmodels$Variable)

levels(allmodels$Variable)[2] <- "Privacy concern (0-3)"
levels(allmodels$Variable)[3] <- "Generalized trust (0-10)"

#allmodels$Variable <- str_wrap(allmodels$Variable, width = 20)

# Specify the width of your confidence intervals
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2)  # 95% multiplier

allmodels$Outcome <- paste(allmodels$Outcome, " Change", sep="")

allmodels$Coefficient_labels <- as.numeric(factor(paste(allmodels$Outcome, allmodels$Model, sep="")))
allmodels$Coefficient_labels <- allmodels$Coefficient_labels + 8
allmodels$Coefficient_labels <- paste(round(allmodels$Coefficient, 2), " (M", allmodels$Coefficient_labels, ")",sep="")
allmodels$Outcome <- gsub("Trust Researchers", "Trust University Researchers", allmodels$Outcome)





# CHANGE ORDER
  allmodels$Outcome <- factor(allmodels$Outcome, 
                              levels = c("Trust Facebook Change", "Trust Google Change", "Trust Fedoffstats Change", "Trust University Researchers Change"),
                              ordered = TRUE)
  allmodels$order1 <- allmodels$Variable
  allmodels$order1 <- recode(allmodels$order1,
    "GDPR Awareness (0 = No Change, 1 = Positive Change)" = "1",
    "Privacy concern (0-3)" = "2",
    "Generalized trust (0-10)" = "3"
  )
  allmodels$order2 <- allmodels$Outcome
  allmodels$order2<- recode(allmodels$order2,
    "Trust Facebook Change" = "1",
    "Trust Google Change" = "2",
    "Trust Fedoffstats Change" = "3",
    "Trust University Researchers Change" = "4"
  )
  allmodels <- allmodels %>% arrange(order1, order2)
  allmodels$plot_order_index <- 1:nrow(allmodels)



# Plot
ggplot(allmodels, aes(x = Variable, y = Coefficient, group = plot_order_index)) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1,
                     shape = Model,
                     colour = Outcome),
                            lwd = 1, position = position_dodge2(reverse = TRUE, width = 0.8)) + 
  geom_pointrange(aes(x = Variable, 
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2,
                      ymax = Coefficient + SE*interval2,
                      shape = Model,
                      colour = Outcome),
                  lwd = 1/2,
                  position = position_dodge2(reverse = TRUE, width = 0.8),
                  fill = "WHITE") +
  geom_text(aes(x = Variable,
                y = Coefficient + SE*interval2+0.15,
                label = Coefficient_labels,
                     shape = Model,
                     colour = Outcome),
            position = position_dodge2(reverse = TRUE, width = 0.8),
            size = 3) +
  coord_flip() + theme_light() +
    labs(colour = "Outcome (Scale: -10 - 10)") +
  labs(shape = "Model Type") +
  scale_x_discrete(limits = rev(levels(allmodels$Variable)), 
                   labels = str_wrap(rev(levels(allmodels$Variable)), width = 16)) + 
  scale_colour_discrete(labels = function(x) str_wrap(x, width = 22)) +
  ylim(NA, 0.85)

ggsave("./figure5.png", width = 7, height = 4)
```


## Table A7/Figure 6: Experiment
* Unclear what we see in that table...*

Coefficient and standard errors (in parentheses) from an OLS regression predicting change in trust before and after the experimental treatment (GDPR information).

```{r table3, results="asis"}
# Reduced models, with treatment as only independent variable
# CHECK: Exclude 5 Respondents that skipped a wave? N = 2117 vs. 2112
trust.google.change.m1.tr.fac.red <- lm(trust.google.change ~ tr.fac,
  subset = wave.num == 3, data = data
)

trust.facebook.change.m1.tr.fac.red <- lm(trust.facebook.change ~ tr.fac,
subset = wave.num == 3, data = data
)

trust.generalized.change.m1.tr.fac.red <- lm(trust.generalized.change ~ tr.fac,
subset = wave.num == 3, data = data
)

# Models with treatment as factor, all
trust.google.change.m1.tr.fac <- lm(trust.google.change ~ tr.fac + gdpr.know.num + (tr.fac * gdpr.know.num),
  subset = wave.num == 3, data = data
)

trust.facebook.change.m1.tr.fac <- lm(trust.facebook.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3, data = data
)

trust.generalized.change.m1.tr.fac <- lm(trust.generalized.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3, data = data
)

# Models with treatment as factor, those who assessed treatment text as somewhat or very comprehensible
trust.google.change.m2.tr.fac <- lm(trust.google.change ~ tr.fac + gdpr.know.num + (tr.fac * gdpr.know.num),
  subset = wave.num == 3 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)

trust.facebook.change.m2.tr.fac <- lm(trust.facebook.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)

trust.generalized.change.m2.tr.fac <- lm(trust.generalized.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)


stargazer(trust.google.change.m1.tr.fac.red, trust.google.change.m1.tr.fac, trust.google.change.m2.tr.fac,
  trust.facebook.change.m1.tr.fac.red, trust.facebook.change.m1.tr.fac, trust.facebook.change.m2.tr.fac,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Outcomes:",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Trust Google (pre-post)", "Trust Facebook (pre-post)",
    "Trust generalized (pre-post)"
  ),
  column.separate = c(3, 3, 3),
  model.names = FALSE,
  model.numbers = FALSE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = "* Wave 3: (1) and (2) all respondents, (3) excluding those who assessed treatment text as not at all or little comprehensible",
  header = FALSE,
  no.space = TRUE,
  font.size = "footnotesize",
  covariate.labels = c(
    "Treatment GDPR (Ref.: None)",
    "Treatment PassRights (Ref.: None)",
    "Know GDPR (No = 0, Yes = 1)",
    "Treatment GDPR*Awareness",
    "Treatment PassRights*Awareness"
  ),
  out = "./tableA7.html"
)
```



```{r figure8-of-table3}

models <- c("trust.google.change.m1.tr.fac.red", 
            "trust.google.change.m1.tr.fac", 
            "trust.google.change.m2.tr.fac",
            "trust.facebook.change.m1.tr.fac.red", 
            "trust.facebook.change.m1.tr.fac", 
            "trust.facebook.change.m2.tr.fac")

allmodels <- NULL
for(i in 1:length(models)){
  fit_i <- get(models[i])
  modelname_i <- models[i]
  outcome_i <- as.character(formula(fit_i))[2]
  if(str_detect(models[i], "m1")){sample_i <- "Full Sample"}else{sample_i <- "Subsample:\nVery/Somewhat\ncomprehensible"}


  
  
model_i <- tidy(fit_i) %>% 
     rename("Variable" = "term") %>% 
       rename("Coefficient" = "estimate") %>% 
       rename("SE" = "std.error") %>%
      # mutate(Model = sub('.*\\.', '', name_i)) %>%
      mutate(Outcome = outcome_i) %>%
  filter(Variable!="(Intercept)") %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(Variable))) %>%
  mutate(Variable = factor(Variable, ordered = TRUE, levels=rev(levels(Variable))))

if(str_detect(models[i], "red")){model_i$Model_Type <- "No Controls"}else{model_i$Model_Type <- "With Controls"}
model_i$Sample <- sample_i
allmodels <- data.frame(rbind(allmodels, model_i)) 
    
}  


allmodels$Variable <- recode(allmodels$Variable,
                             "tr.facGDPR" = "Treatment GDPR (Ref.: None)",
                             "tr.facPassRights" = "Treatment PassRights (Ref.: None)",
                             "gdpr.know.num" = "Know GDPR (No = 0, Yes = 1)",
                             "tr.facGDPR:gdpr.know.num" = "Treatment GDPR * Awareness",
                             "tr.facPassRights:gdpr.know.num" = "Treatment PassRights * Awareness")




allmodels$Outcome <- gsub("\\.", " ", allmodels$Outcome)
allmodels$Outcome <- str_to_title(allmodels$Outcome) 

allmodels$Model[allmodels$Model=="withcontrols"] <- "With Controls"
allmodels$Model[allmodels$Model=="nocontrols"] <- "No Controls"
                         
allmodels$Variable <- droplevels(allmodels$Variable)

#allmodels$Variable <- str_wrap(allmodels$Variable, width = 20)

# Specify the width of your confidence intervals
interval1 <- -qnorm((1-0.9)/2)  # 90% multiplier
interval2 <- -qnorm((1-0.95)/2)  # 95% multiplier

allmodels <- allmodels %>% arrange(Outcome)
allmodels$Coefficient_labels <- as.numeric(factor(paste(allmodels$Outcome, allmodels$Model, allmodels$Sample, sep=""))) + 16
allmodels$Coefficient_labels <- recode(allmodels$Coefficient_labels, 
                                       "17" = "20",
                                       "18" = "21",
                                       "19" = "22",
                                       "20" = "17",
                                       "21" = "18",
                                       "22" = "19")
allmodels$Coefficient_labels <- paste(round(allmodels$Coefficient, 2), " (M", allmodels$Coefficient_labels, ")",sep="")

# allmodels$Sample <- factor(allmodels$Sample, 
#                                       levels = c("Very/Somewhat", "Full Sample"),
#                                       ordered = TRUE)

# allmodels$Model_Type <- factor(allmodels$Model_Type, 
#                                       levels = c("With Controls", "No Controls"))
# 


# Plot
p1 <- ggplot(allmodels %>% filter(str_detect(Outcome, "Google")), aes(colour = Sample)) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1,
                     shape = Model,
                     colour = Sample),
                            lwd = 1, position = position_dodge2(reverse = TRUE, width = 0.8)) + 
  geom_pointrange(aes(x = Variable, 
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2,
                      ymax = Coefficient + SE*interval2,
                      shape = Model,
                      colour = Sample),
                  lwd = 1/2,
                  position = position_dodge2(reverse = TRUE, width = 0.8),
                  fill = "WHITE") +
  geom_text(aes(x = Variable,
                y = Coefficient + SE*interval2+0.2,
                label = Coefficient_labels,
                     shape = Model,
                     colour = Sample),
            position = position_dodge2(reverse = TRUE, width = 0.8),
            size = 3) +
  coord_flip() + 
    labs(shape = "Model Type") +
  scale_x_discrete(limits = rev(levels(allmodels$Variable)), 
                   labels = str_wrap(rev(levels(allmodels$Variable)), width = 20)) + 
  labs(colour = "Sample") +
  theme_light() + ggtitle("Outcome: Trust Google Change\n(-10 - 10)") +
  theme(legend.position="bottom",
        legend.title=element_text(size=8), 
        legend.text=element_text(size=8),
        plot.title = element_text(size = 11)) +
  ylim(NA,0.6)


p2 <- ggplot(allmodels %>% filter(str_detect(Outcome, "Facebook")), aes(colour = Sample)) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
  geom_linerange(aes(x = Variable, 
                     ymin = Coefficient - SE*interval1,
                     ymax = Coefficient + SE*interval1,
                     shape = Model,
                     colour = Sample),
                            lwd = 1, position = position_dodge2(reverse = TRUE, width = 0.8)) + 
  geom_pointrange(aes(x = Variable, 
                      y = Coefficient, 
                      ymin = Coefficient - SE*interval2,
                      ymax = Coefficient + SE*interval2,
                      shape = Model,
                      colour = Sample),
                  lwd = 1/2,
                  position = position_dodge2(reverse = TRUE, width = 0.8),
                  fill = "WHITE") +
  geom_text(aes(x = Variable,
                y = Coefficient + SE*interval2+0.2,
                label = Coefficient_labels,
                     shape = Model,
                     colour = Sample),
            position = position_dodge2(reverse = TRUE, width = 0.8),
            size = 3) +
  coord_flip() + 
    labs(shape = "Model Type") +
  scale_x_discrete(limits = rev(levels(allmodels$Variable)), 
                   labels = str_wrap(rev(levels(allmodels$Variable)), width = 20)) + 
  labs(colour = "Sample") +
  theme_light() + ggtitle("Outcome: Trust Facebook Change\n(-10 - 10)") +
  theme(axis.text.y=element_blank(),
        axis.title.y=element_blank(),
        plot.title = element_text(size = 11)) +
  ylim(NA,0.6)



mylegend<-g_legend(p1)




g <- grid.arrange(arrangeGrob(p1 + theme(legend.position="none"),
                                        p2 + theme(legend.position="none"),
                                   nrow=1, widths=c(1,0.65)),
                  mylegend,
                   #left = grid::textGrob("Variable", rot = 90, vjust = 1),
                   #bottom = grid::textGrob("Coefficient", rot = 0, vjust = 0.5),
                   nrow=2, heights=c(10, 1))
walk(c('png'), ~ ggsave(filename = file.path(paste0("figure6.", .x)), device = .x, plot = g, width = 7, height = 4))



#ggsave("./figure6.png", width = 7, height = 4)
```



```{r table3-speeders, results="asis"}
# Same models as in table3-gdpr-m1-m3-treatmentfactor, but excluding speeders

# Reduced models, with treatment as only independent variable
trust.google.change.m1.tr.fac.red.speeding <- lm(trust.google.change ~ tr.fac,
  subset = wave.num == 3 & speeding == 0, data = data
)

trust.facebook.change.m1.tr.fac.red.speeding <- lm(trust.facebook.change ~ tr.fac,
subset = wave.num == 3 & speeding == 0, data = data
)

trust.generalized.change.m1.tr.fac.red.speeding <- lm(trust.generalized.change ~ tr.fac,
subset = wave.num == 3 & speeding == 0, data = data
)

# Models with treatment as factor, all
trust.google.change.m1.tr.fac.speeding <- lm(trust.google.change ~ tr.fac + gdpr.know.num + (tr.fac * gdpr.know.num),
  subset = wave.num == 3 & speeding == 0, data = data
)

trust.facebook.change.m1.tr.fac.speeding <- lm(trust.facebook.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & speeding == 0, data = data
)

trust.generalized.change.m1.tr.fac.speeding <- lm(trust.generalized.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & speeding == 0, data = data
)

# Models with treatment as factor, those who assessed treatment text as somewhat or very comprehensible
trust.google.change.m2.tr.fac.speeding <- lm(trust.google.change ~ tr.fac + gdpr.know.num + (tr.fac * gdpr.know.num),
  subset = wave.num == 3 & speeding == 0 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)

trust.facebook.change.m2.tr.fac.speeding <- lm(trust.facebook.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & speeding == 0 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)

trust.generalized.change.m2.tr.fac.speeding <- lm(trust.generalized.change ~ tr.fac + gdpr.know.num +
  (tr.fac * gdpr.know.num),
subset = wave.num == 3 & speeding == 0 & (text.comprehensible.dich == 1 | is.na(text.comprehensible.dich == 1) == TRUE), data = data
)


stargazer(trust.google.change.m1.tr.fac.red.speeding, trust.google.change.m1.tr.fac.speeding, trust.google.change.m2.tr.fac.speeding,
  trust.facebook.change.m1.tr.fac.red.speeding, trust.facebook.change.m1.tr.fac.speeding, trust.facebook.change.m2.tr.fac.speeding,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Outcomes:",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Trust Google (pre-post)", "Trust Facebook (pre-post)",
    "Trust generalized (pre-post)"
  ),
  column.separate = c(3, 3, 3),
  model.names = FALSE,
  model.numbers = FALSE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = "* Wave 3: (1) and (2) non-speeders (threshold: at least 0.3 seconds per word), (3) excluding those who assessed treatment text as no or little comprehensible",
  header = FALSE,
  no.space = TRUE,
  font.size = "footnotesize",
  covariate.labels = c(
    "Treatment GDPR (Ref.: None)",
    "Treatment PassRights (Ref.: None)",
    "Know GDPR (No = 0, Yes = 1)",
    "Treatment GDPR*Awareness",
    "Treatment PassRights*Awareness"
  ),
  out = "./table3-speeding.html"
)
```

<br><br><br>




# Appendix
## Table A2-A, A2-A, A3-A, A3-B, A4-A, A4-B: Summary stats


```{r tableA2-A.html, results="asis"}
summary.stats <- data %>% filter(wave.num == 1) %>% select(-pid) %>% select("trust.google", "trust.facebook", "trust.researchers", "trust.fedoffstats", "gdpr.know.new",
                                                                                                      "female", "age.cat.fac", "school.educ.num4.fact", "privacy.worry.numeric", "account.facebook.fac", "account.google.fac", "device.smartphone.dummy", "device.handy.dummy", "device.desktop.dummy", "device.tablet.dummy", "device.ereader.dummy", "trust.generalized")


summary.stats <- summary.stats %>% rename("Trust Google" = "trust.google", 
                         "Trust Facebook" = "trust.facebook", 
                         "Trust Researchers" = "trust.researchers", 
                         "Trust Fedoffstats" = "trust.fedoffstats", 
                         "GDPR Awareness" = "gdpr.know.new",
                         "Female" = "female", 
                         "Age (cat.)" = "age.cat.fac", 
                         "Education (cat.)" = "school.educ.num4.fact", 
                         "Privacy worry" = "privacy.worry.numeric", 
                         "Account: Facebook (cat.)" = "account.facebook.fac", 
                         "Account: Google (cat.)" = "account.google.fac", 
                         "Device: Smartphone" = "device.smartphone.dummy", 
                         "Device: Handy" = "device.handy.dummy", 
                         "Device: Tablet" = "device.desktop.dummy", 
                         "Device: PC" = "device.tablet.dummy", 
                         "Device: Ereader" = "device.ereader.dummy", 
                         "Generalized Trust" = "trust.generalized")


summary.stats.num <-  summary.stats  %>% select_if(is.numeric)
summary.stats.fac <-  summary.stats  %>% select_if(is.factor)



stargazer::stargazer(summary.stats.num ,
  iqr = FALSE,
  summary = TRUE,
  type = "html",
  font.size = "footnotesize",
  table.placement = "H",
  title = "Wave 1",
  digits = 2,
  rownames = FALSE,
  header = FALSE,
  notes = "\\parbox[t]{7cm}{Note: Summary statistics for numeric variables.}", # \\textwidth
  notes.append = FALSE,
  notes.align = "l",
  out = "./tableA2-A.html"
)



# Categorical variables
  library(magrittr)
  library(qwraps2)
  options(qwraps2_markup = "markdown")
  summary.table <- summary.stats.fac %>%
      summary_table(.)
  x <- capture.output(print(summary.table, caption = "Summary statistics: Categorical variables", markup = "markdown",
        rtitle = "Variable",
        cnames = c("Distribution (N/Prop.)")
        ))
  cat(x,file="./tableA2-B.Rmd",append=FALSE,sep="\n")
  markdownToHTML(file = "./tableA2-B.Rmd", output = "tableA2-B.html")
```

```{r tableA3-A.html, results="asis"}
summary.stats <- data %>% filter(wave.num == 2) %>% select(-pid) %>% select("trust.google", "trust.facebook", "trust.researchers", "trust.fedoffstats", "gdpr.know.new",
                                                                                                      "female", "age.cat.fac", "school.educ.num4.fact", "privacy.worry.numeric", "account.facebook.fac", "account.google.fac", "device.smartphone.dummy", "device.handy.dummy", "device.desktop.dummy", "device.tablet.dummy", "device.ereader.dummy", "trust.generalized")


summary.stats <- summary.stats %>% rename("Trust Google" = "trust.google", 
                         "Trust Facebook" = "trust.facebook", 
                         "Trust Researchers" = "trust.researchers", 
                         "Trust Fedoffstats" = "trust.fedoffstats", 
                         "GDPR Awareness" = "gdpr.know.new",
                         "Female" = "female", 
                         "Age (cat.)" = "age.cat.fac", 
                         "Education (cat.)" = "school.educ.num4.fact", 
                         "Privacy worry" = "privacy.worry.numeric", 
                         "Account: Facebook (cat.)" = "account.facebook.fac", 
                         "Account: Google (cat.)" = "account.google.fac", 
                         "Device: Smartphone" = "device.smartphone.dummy", 
                         "Device: Handy" = "device.handy.dummy", 
                         "Device: Tablet" = "device.desktop.dummy", 
                         "Device: PC" = "device.tablet.dummy", 
                         "Device: Ereader" = "device.ereader.dummy", 
                         "Generalized Trust" = "trust.generalized")


summary.stats.num <-  summary.stats  %>% select_if(is.numeric)
summary.stats.fac <-  summary.stats  %>% select_if(is.factor)



stargazer::stargazer(summary.stats.num ,
  iqr = FALSE,
  summary = TRUE,
  type = "html",
  font.size = "footnotesize",
  table.placement = "H",
  title = "Wave 2",
  digits = 2,
  rownames = FALSE,
  header = FALSE,
  notes = "\\parbox[t]{7cm}{Note: Summary statistics for numeric variables.}", # \\textwidth
  notes.append = FALSE,
  notes.align = "l",
  out = "./tableA3-A.html"
)



# Categorical variables
  library(magrittr)
  library(qwraps2)
  options(qwraps2_markup = "markdown")
  summary.table <- summary.stats.fac %>%
      summary_table(.)
  x <- capture.output(print(summary.table, caption = "Summary statistics: Categorical variables", markup = "markdown",
        rtitle = "Variable",
        cnames = c("Distribution (N/Prop.)")
        ))
  cat(x,file="./tableA3-B.Rmd",append=FALSE,sep="\n")
  markdownToHTML(file = "./tableA3-B.Rmd", output = "tableA3-B.html")
```
<br><br><br>


```{r tableA4-A.html, results="asis"}
summary.stats <- data %>% filter(wave.num == 3) %>% select(-pid) %>% select("trust.google", "trust.facebook", "trust.researchers", "trust.fedoffstats", "gdpr.know.new",
                                                                                                      "female", "age.cat.fac", "school.educ.num4.fact", "privacy.worry.numeric", "account.facebook.fac", "account.google.fac", "device.smartphone.dummy", "device.handy.dummy", "device.desktop.dummy", "device.tablet.dummy", "device.ereader.dummy", "trust.generalized")


summary.stats <- summary.stats %>% rename("Trust Google" = "trust.google", 
                         "Trust Facebook" = "trust.facebook", 
                         "Trust Researchers" = "trust.researchers", 
                         "Trust Fedoffstats" = "trust.fedoffstats", 
                         "GDPR Awareness" = "gdpr.know.new",
                         "Female" = "female", 
                         "Age (cat.)" = "age.cat.fac", 
                         "Education (cat.)" = "school.educ.num4.fact", 
                         "Privacy worry" = "privacy.worry.numeric", 
                         "Account: Facebook (cat.)" = "account.facebook.fac", 
                         "Account: Google (cat.)" = "account.google.fac", 
                         "Device: Smartphone" = "device.smartphone.dummy", 
                         "Device: Handy" = "device.handy.dummy", 
                         "Device: Tablet" = "device.desktop.dummy", 
                         "Device: PC" = "device.tablet.dummy", 
                         "Device: Ereader" = "device.ereader.dummy", 
                         "Generalized Trust" = "trust.generalized")


summary.stats.num <-  summary.stats  %>% select_if(is.numeric)
summary.stats.fac <-  summary.stats  %>% select_if(is.factor)



stargazer::stargazer(summary.stats.num ,
  iqr = FALSE,
  summary = TRUE,
  type = "html",
  font.size = "footnotesize",
  table.placement = "H",
  title = "Wave 3",
  digits = 2,
  rownames = FALSE,
  header = FALSE,
  notes = "\\parbox[t]{7cm}{Note: Summary statistics for numeric variables.}", # \\textwidth
  notes.append = FALSE,
  notes.align = "l",
  out = "./tableA4-A.html"
)



# Categorical variables
  library(magrittr)
  library(qwraps2)
  options(qwraps2_markup = "markdown")
  summary.table <- summary.stats.fac %>%
      summary_table(.)
  x <- capture.output(print(summary.table, caption = "Summary statistics: Categorical variables", markup = "markdown",
        rtitle = "Variable",
        cnames = c("Distribution (N/Prop.)")
        ))
  cat(x,file="./tableA4-B.Rmd",append=FALSE,sep="\n")
  markdownToHTML(file = "./tableA4-B.Rmd", output = "tableA4-B.html")
```
<br><br><br>



## Figure A1: Distributions of changes from Wave 1 to Wave 2 for different variables

Graph displays changes from Wave 1 to Wave 2 for trust variables and gdpr variable. Respondents with wrong treatment status (1 -> 0 and 1 -> 1) are excluded.




```{r figureA1-changes, message=FALSE, warning=FALSE, paged.print=FALSE}
#  Plot of changes W1 to W2
p1 <- ggplot(data.w1w2, aes(trust.google.diff)) +
  geom_histogram(fill="black") +
  ylab("Number of respondents") +
  xlab("Google") + theme_light()
p2 <- ggplot(data.w1w2, aes(trust.facebook.diff)) +
  geom_histogram(fill="black") +
  ylab("Number of respondents") +
  xlab("Facebook")+ theme_light()
p3 <- ggplot(data.w1w2, aes(trust.researchers.diff)) +
  geom_histogram(fill="black") +
  ylab("Number of respondents") +
  xlab("Researchers")+ theme_light()
p4 <- ggplot(data.w1w2, aes(trust.fedoffstats.diff)) +
  geom_histogram(fill="black") +
  ylab("Number of respondents") +
  xlab("Fed. Stats. Office")+ theme_light()
p5 <- ggplot(data.w1w2, aes(gdpr.know.num.diff)) +
  geom_histogram(fill="black") +
  ylab("Number of respondents") +
  xlab("GDPR")+ theme_light()


png("./figureA1.png")
plot <- grid.arrange(p1, p2, p3, p4, p5, nrow = 3)
dev.off()
grid.arrange(p1, p2, p3, p4, p5, nrow = 3)
```   

<br><br><br>



<br><br><br>



## Figure A2: Random assignment

```{r figureA3-treatments, message=FALSE, warning=FALSE, paged.print=FALSE}

ggplot(data %>% filter(!is.na(randomization_gdprinfo_str)), aes(x=randomization_gdprinfo_str))+
  geom_bar(stat="count", width=0.7, fill = "black")+
  theme_light() +
  ylab("Number of respondents (only Wave 3)") +
  xlab("Treatment assignment in Wave 3") +
  scale_x_discrete(labels = c("GDPR\n Information", "No Information", "Air Passenger Right\n Information"))

ggsave("./figureA2.png", width = 7, height = 4)
```

![](./figureA2.png)

<br><br><br>




## Figure A3: Participation across waves

```{r figA3-participation-across-waves}
# Expand to get dataset with rows for non observations
data.expand <- data %>% expand(pid, wave.num)

# Right_Join with longformat data to real presence of respondents
data.expand <- data %>% right_join(data.expand) %>% arrange(pid, wave.num)

# Subset variables
data.expand <- data.expand %>% select(pid, wave.num, wave) # %>% distinct()

# Spread dataset and arrange
data.expand <- data.expand %>% spread(wave.num, wave) %>% arrange(pid)

# Rename wave variables
data.expand <- rename(data.expand, wave1 = "1", wave2 = "2", wave3 = "3")

# Create "across_waves" with information of presence in single waves
data.expand <- unite(data.expand, across_waves, -pid)

# Aggregate to get observations per presence in different waves
data.expand <- data.expand %>% group_by(across_waves) %>% summarize(n = n())

# Separate united variable
data.expand <- data.expand %>% separate(across_waves, c("Wave1", "Wave2", "Wave3"), sep = "_")

# Replace values of wave variables with N values
data.expand$Wave1[data.expand$Wave1 != "NA"] <- data.expand$n[data.expand$Wave1 != "NA"]
data.expand$Wave2[data.expand$Wave2 != "NA"] <- data.expand$n[data.expand$Wave2 != "NA"]
data.expand$Wave3[data.expand$Wave3 != "NA"] <- data.expand$n[data.expand$Wave3 != "NA"]

# Delete groups only W2/W3 (N = 3) and only W1/W3 (N = 2)
data.expand <- data.expand %>% filter(n > 5)

# Create barplot illustrating the sampels across waves
data.expand <- gather(data.expand, key = wave, value = samples, -n)
data.expand$samples <- as.numeric(data.expand$samples)

# Raw original data (numbers change after deletion of 10 open-ended responses)
# fill <- factor(data.expand$samples, levels = c("482", "532", "843", "292", "1269"))
# fill.factor.levels <- levels(fill)
# labels <- recode(fill.factor.levels,
#   "532" = "Only W1 (N = 532)",
#   "292" = "W1 and W2 (N = 292)",
#   "1269" = "W1, W2 and W3 (N = 1269)",
#   "482" = "Only W2 (N = 482)",
#   "843" = "Only W3 (N = 843)"
# )

# Anonymized data
fill <- factor(data.expand$samples, levels = c("482", "531", "841", "291", "1263"))
fill.factor.levels <- levels(fill)
labels <- recode(fill.factor.levels,
  "531" = "Only W1 (N = 531)",
  "291" = "W1 and W2 (N = 291)",
  "1263" = "W1, W2 and W3 (N = 1263)",
  "482" = "Only W2 (N = 482)",
  "841" = "Only W3 (N = 841)"
)


# Get per Wave N for x-axis labels
data.expand %>% group_by(wave) %>% summarize(sum(samples, na.rm = T))
data %>% group_by(wave) %>% summarize(n = n())

ggplot(data = data.expand, aes(
  x = wave,
  y = samples,
  fill = fill
)) + geom_bar(stat = "identity") + scale_fill_manual(
  values = c(
    "#e41a1c", "#377eb8",
    "#4daf4a", "#984ea3", "#ff7f00"
  ),
  name = "Participation",
  labels = labels
) + ylab("Sample size") + xlab("Panel wave") + scale_x_discrete(labels = c(
  "Wave 1 (N = 2093)\nApr 16 - 23, 2018",
  "Wave 2 (N = 2043)\nJul 24 - Aug 2, 2018",
  "Wave 3 (N = 2112)\nOct 29 - Nov 7, 2018"
))+ theme_light()

ggsave("./figureA3.png", width = 8, height = 4)
```



<br><br><br>



## Figure A4: Trust means across waves

```{r figureA4}

# Full sample trust means
trust.means.full.sample <- data %>%
  select(
    wave.num,
    trust.google,
    trust.facebook,
    trust.fedoffstats,
    trust.researchers
  ) %>%
  gather(
    key = variable,
    value = value, trust.google:trust.researchers
  ) %>%
  group_by(wave.num, variable) %>%
  summarise_all(funs(mean(., na.rm = TRUE), 
                     n = sum(!is.na(.)), 
                     sd(., na.rm = TRUE))) %>%
  mutate(
    se = sd / sqrt(n),
    ci_95 = qnorm(1 - 0.05/2)*se,
    ci_90 = qnorm(1 - 0.1/2)*se,
    ci_t = qt(1 - (0.05 / 2), n - 1) * se #for comparison
  ) %>%
  mutate(Organization = recode(variable,
    "trust.facebook" = "Facebook",
    "trust.google" = "Google",
    "trust.researchers" = "Researchers",
    "trust.fedoffstats" = "Federal Statistical Office"
  )) %>%
  mutate(participation = "Full Sample")
# Beware to calculate the right n for each variable



# Subsample (participation) trust means
data.expand <- data %>% expand(pid, wave.num)
data.expand <- data %>% right_join(data.expand) %>% arrange(pid, wave.num)
participation <- data.expand %>% group_by(pid) %>% summarise(participation = paste(wave, collapse = "_"))
data.expand <- left_join(data.expand, participation, by = "pid")

trust.means.subsamples <- data.expand %>%
  select(
    wave.num,
    participation,
    trust.google,
    trust.facebook,
    trust.fedoffstats,
    trust.researchers
  ) %>%
  filter(participation != "NA_Wave 2_Wave 3", participation != "Wave 1_NA_Wave 3") %>%
  gather(
    key = variable,
    value = value, trust.google:trust.researchers
  ) %>%
  group_by(wave.num, participation, variable) %>%
  summarise_all(funs(mean(., na.rm = TRUE),
    # n(),
    n = sum(!is.na(.)),
    sd(., na.rm = TRUE)
  )) %>%
  mutate(
    se = sd / sqrt(n),
    ci_95 = qnorm(1 - 0.05/2)*se,
    ci_90 = qnorm(1 - 0.1/2)*se,
    ci_t = qt(1 - (0.05 / 2), n - 1) * se #for comparison
  ) %>%
  mutate(Organization = recode(variable,
    "trust.facebook" = "Facebook",
    "trust.google" = "Google",
    "trust.researchers" = "Researchers",
    "trust.fedoffstats" = "Federal Statistical Office"
  )) %>%
  arrange(wave.num, Organization, participation)



# Bind fulls sample and subsamples
means <- bind_rows(trust.means.full.sample, trust.means.subsamples)

# Add lables for graph
means <- means %>%
  mutate(label = recode(participation,
    "Wave 1" = "Full Sample",
    "Wave 2" = "Full Sample",
    "Wave 3" = "Full Sample",
    "NA_NA_Wave 3" = "Only W3",
    "NA_Wave 2_NA" = "Only W2",
    "Wave 1_NA_NA" = "Only W1",
    "Wave 1_Wave 2_NA" = "W1 and W2",
    "Wave 1_Wave 2_Wave 3" = "W1, W2 and W3"
  ))

# Only visualize trust means for full sample
means <- means %>% filter(label == "Full Sample")

means$Organization <- recode(means$Organization, "Researchers" = "University Researchers")

# means$Organization <- paste(means$Organization, " (full sample)", sep ="")

means$order1 <- means$wave.num
means$order2 <- recode(means$Organization,
  "Google" = "1",
  "Facebook" = "2",
  "Federal Statistical Office" = "3",
  "University Researchers" = "4"
)

means <- means %>% arrange(order1, order2)


means$Organization <- factor(means$Organization,
  levels = c(
    "Facebook",
    "Google",

    "Federal Statistical Office",
    "University Researchers"
  )
)

pd <- position_dodge(.6)


ggplot(means, 
       aes(
  x = wave.num,
  y = mean,
  colour = Organization,
  group = Organization
)) +
    geom_errorbar(aes(ymin = mean - ci_90, 
                    ymax = mean + ci_90), 
                colour="black",
                size = 1,
                width = 0.0, 
                position = pd, 
                linetype = "solid") +
      geom_errorbar(aes(ymin=mean - ci_95, 
                    ymax=mean + ci_95,
                    color = factor(label)), 
                colour="black",
                size = 0.4,
                width=.1, 
                position=pd) +
  geom_line(position = pd, size = 0.6) +
  geom_point(position = pd, size = 1) +

  scale_x_continuous(breaks = c(1, 2, 3), labels = c(
    "Wave 1 (N = 2093)\nApr 16 - 23, 2018",
    "Wave 2 (N = 2043)\nJul 24 - Aug 02, 2018",
    "Wave 3 (N = 2112)\nOct 29 - Nov 07, 2018"
  )) +
  theme_light() +
  theme(axis.title.x = element_blank()) +
  ylim(0, 10) +
  ylab("Average trust on a scale\nfrom 0 = 'Not at all' to 10 = 'Completely'")
ggsave("./figureA4.png", width = 7, height = 4)
```


<br><br><br>


## TAble A5: Balance statistics across three groups
Table \@ref(tab:table-balance-stats) provides balance statistics for sex and age.


```{r tableA4-balance-stats, message=FALSE, warning=FALSE, paged.print=FALSE, results="asis"}

by.group <- group_by(data, randomization_gdprinfo_str) %>%
  summarise(
    mean.sex = mean(female,
      na.rm = TRUE
    ),
    mean.age = mean(age,
      na.rm = TRUE
    ),
    mean.gdpr.know.new = mean(gdpr.know.new,
      na.rm = TRUE
    ),
    mean.account.facebook.dummy = mean(data$account.facebook.dummy,
      na.rm = TRUE
    ),
    mean.account.google.dummy = mean(data$account.google.dummy,
      na.rm = TRUE
    ),
    n.total = n()
  )

by.group.display <- data.frame(by.group)
by.group.display <- by.group.display[-4, ]
by.group.display <- data.frame(t(by.group.display))
variable <- rownames(by.group.display)[-1]
by.group.display <- by.group.display[-1, ]
names(by.group.display) <- c("GDPR", "None", "PassRights")
by.group.display <- by.group.display %>% mutate_if(is.factor, funs(as.character(.))) %>% mutate_if(is.character, funs(as.numeric(.))) %>% mutate_if(is.numeric, funs(round(., 2)))
by.group.display$variable <- variable

by.group.display <- by.group.display %>% select(4, 1, 2, 3)


table.balance <- knitr::kable(by.group.display,
  row.names = FALSE,
  caption = "Balance Statistics and observations", format = "html", booktabs = T
) %>%
  kable_styling(full_width = T, font_size = 12)

table.balance
save_kable(table.balance, "tableA5-balance.html", self_contained = TRUE)
```



<br><br><br>

## Table A8: Effects in subsets

* Create subsets of the data

```{r generate-data-subsets-tableA8, echo=TRUE}
# Devices
table(data.did$number.devices)
data.did.number.devices.low <- data.did %>% filter(number.devices<=2)
data.did.number.devices.high <- data.did %>% filter(number.devices>=4)
```  



```{r tableA8, echo=TRUE, results="asis"}
# Estimate models looping over datasets.


subsets <- ls()[grepl("data\\.did\\.", ls())]


for(y in subsets){
  
# Exclude controls that conflict with subsetting variables
  if(str_detect(y, "abitur")){
    controls <- controls[!str_detect(controls, "educ")]
  }
  if(str_detect(y, "privacy.worry")){
    controls <- controls[!str_detect(controls, "privacy.worry")]
  }  


# Lm models for comparison of intercepts
outcomes <- c("trust.google.diff", "trust.facebook.diff", "trust.fedoffstats.diff", "trust.researchers.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = get(y)))

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = get(y)))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel).",
            paste("Respondents of data subset ", gsub("data.did.", "",y), sep = "")),
  header = FALSE,
  no.space = TRUE,
  font.size = "tiny",
  out = paste("tableA9-subset-", gsub("\\.", "-", gsub("data.did.", "",y)), ".html", sep="")
)
}
```




## FigA5: Correlation matrices


```{r fig-A5, echo=FALSE, fig.align="center", fig.cap="Correlation plot: Privacy concern, generalized trust and trust judgments", fig.height=7, message=FALSE, warning=FALSE, paged.print=FALSE}

data_cor <- data %>%
  filter(wave == "Wave 1") %>%
  select(
    privacy.worry.numeric,
    trust.generalized,
    trust.google,
    trust.facebook,
    trust.researchers,
    trust.fedoffstats
  )

names(data_cor) <- gsub(
  "Fb", "Facebook",
  str_to_title(gsub("\\.", " ", gsub("_num", "", names(data_cor))))
)
names(data_cor) <- gsub(" Numeric", "",names(data_cor))
names(data_cor) <- gsub(" ", "\n",names(data_cor))


correlation_matrix <- round(cor(data_cor, use = "pairwise.complete.obs"), 1)

# Plot

p1 <- ggcorrplot(correlation_matrix,
  hc.order = TRUE,
  type = "lower",
  lab = TRUE,
  tl.cex = 9,
  show.diag = TRUE
) + ggtitle("Data: Wave 1")



# Wave 2
data_cor <- data %>%
  filter(wave == "Wave 2") %>%
  select(
    privacy.worry.numeric,
    trust.generalized,
    trust.google,
    trust.facebook,
    trust.researchers,
    trust.fedoffstats
  )

names(data_cor) <- gsub(
  "Fb", "Facebook",
  str_to_title(gsub("\\.", " ", gsub("_num", "", names(data_cor))))
)
names(data_cor) <- gsub(" Numeric", "",names(data_cor))
names(data_cor) <- gsub(" ", "\n",names(data_cor))

correlation_matrix <- round(cor(data_cor, use = "pairwise.complete.obs"), 1)

# Plot

p2 <- ggcorrplot(correlation_matrix,
  hc.order = TRUE,
  type = "lower",
  lab = TRUE,
  tl.cex = 9,
  show.diag = TRUE
) + ggtitle("Data: Wave 2")


# Wave 3
data_cor <- data %>%
  filter(wave == "Wave 3") %>%
  select(
    privacy.worry.numeric,
    trust.generalized,
    trust.google,
    trust.facebook,
    trust.researchers,
    trust.fedoffstats
  )

names(data_cor) <- gsub(
  "Fb", "Facebook",
  str_to_title(gsub("\\.", " ", gsub("_num", "", names(data_cor))))
)
names(data_cor) <- gsub(" Numeric", "",names(data_cor))
names(data_cor) <- gsub(" ", "\n",names(data_cor))

correlation_matrix <- round(cor(data_cor, use = "pairwise.complete.obs"), 1)

# Plot

p3 <- ggcorrplot(correlation_matrix,
  hc.order = TRUE,
  type = "lower",
  lab = TRUE,
  tl.cex = 9,
  show.diag = TRUE
) + ggtitle("Data: Wave 3")




graph_combined <- ggarrange(p1, p2, p3,
  common.legend = TRUE,
  legend = "bottom",
  ncol = 2,
  nrow = 2
)
graph_combined
ggsave("./figureA5.png", width = 6, height = 7)
```


## Table A10:  Outcome privacy worry

```{r tableA10-privacy-worry, echo=TRUE, results="asis"}
# Lm models for comparison of intercepts
outcomes <- c("privacy.worry.numeric.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did)
         )

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Privacy concern",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  # column.labels = c(
  #   "Google",
  #   "Facebook",
  #   "Federal Stat. Office",
  #   "Univ. Researchers"
  # ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel)."),
  header = FALSE,
  no.space = TRUE,
  # covariate.labels = c(
  #   "GDPR Awareness (0 = No Change, 1 = Positive Change)",
  #   "Female",
  #   "Age: 30-49 (ref.:<30)",
  #   "Age: >=50 (ref.:<30)",
  #   "Education (ref. Hauptschule): Mittlere Reife",
  #   "Education (ref. Hauptschule): Fachabitur",
  #   "Education (ref. Hauptschule): Abitur",
  #   "Privacy concern",
  #   "Account Facebook: No, but before (ref.: Never)",
  #   "Account Facebook: Yes (ref.: Never)",
  #   "Account Google: No, but before (ref.: Never)",
  #   "Account Google: Yes (ref.: Never)",
  #   "Device: Smartphone",
  #   "Device: Cell phone (no smartphone)",
  #   "Device: Desktop/Laptop",
  #   "Device: Tablet",
  #   "Device: eReader",
  #   "Generalized trust"),
  font.size = "tiny",
  out = "./tableA10.html"
)
```




## Table A11:  Outcome generalized trust

```{r tableA11-generalized-trust, echo=TRUE, results="asis"}
# Lm models for comparison of intercepts
outcomes <- c("trust.generalized.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did)
         )

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Generalized trust",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  # column.labels = c(
  #   "Google",
  #   "Facebook",
  #   "Federal Stat. Office",
  #   "Univ. Researchers"
  # ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel)."),
  header = FALSE,
  no.space = TRUE,
  # covariate.labels = c(
  #   "GDPR Awareness (0 = No Change, 1 = Positive Change)",
  #   "Female",
  #   "Age: 30-49 (ref.:<30)",
  #   "Age: >=50 (ref.:<30)",
  #   "Education (ref. Hauptschule): Mittlere Reife",
  #   "Education (ref. Hauptschule): Fachabitur",
  #   "Education (ref. Hauptschule): Abitur",
  #   "Privacy concern",
  #   "Account Facebook: No, but before (ref.: Never)",
  #   "Account Facebook: Yes (ref.: Never)",
  #   "Account Google: No, but before (ref.: Never)",
  #   "Account Google: Yes (ref.: Never)",
  #   "Device: Smartphone",
  #   "Device: Cell phone (no smartphone)",
  #   "Device: Desktop/Laptop",
  #   "Device: Tablet",
  #   "Device: eReader",
  #   "Generalized trust"),
  font.size = "tiny",
  out = "./tableA11.html"
)
```


## Digital literacy robustness


```{r tableA5-digital-literacy, results="asis"}

# Models that use number.devices rather the device dummies as control

treatment <- "gdpr.know.new"
controls <- c("female", "age.cat.fac", "school.educ.num4.fact", "privacy.worry.numeric", "account.facebook.fac", "account.google.fac", "number.devices", "trust.generalized")


as.formula(paste("trust.google", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ "))

tab1.trust.google.w1 <- lm(trust.google ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.facebook.w1 <- lm(trust.facebook ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.fedoffstats.w1 <- lm(trust.fedoffstats ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)
tab1.trust.researchers.w1 <- lm(trust.researchers ~ gdpr.know.new,
  subset = wave.num == 1,
  data = data
)

tab1.trust.google.w1.full <- lm(as.formula(paste("trust.google", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.facebook.w1.full <- lm(as.formula(paste("trust.facebook", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.fedoffstats.w1.full <- lm(as.formula(paste("trust.fedoffstats", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

tab1.trust.researchers.w1.full <- lm( as.formula(paste("trust.researchers", paste(treatment, paste(controls, collapse = " + "), sep = " + "), sep = " ~ ")),
subset = wave.num == 1, data = data
)

stargazer(tab1.trust.google.w1, tab1.trust.google.w1.full,
  tab1.trust.facebook.w1, tab1.trust.facebook.w1.full,
  tab1.trust.fedoffstats.w1, tab1.trust.fedoffstats.w1.full,
  tab1.trust.researchers.w1, tab1.trust.researchers.w1.full,
  type = "html",
  dep.var.labels.include = FALSE,
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  # model.names = paste("(M", 1:8,")", sep=""),
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:pooled",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2),
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents in Wave 1."),
  header = FALSE,
  no.space = TRUE,
  font.size = "tiny",
  # covariate.labels = c(
  #   "GDPR Awareness (No = 0, Yes = 1)",
  #   "Female",
  #   "Age: 30-49 (ref.:<30)",
  #   "Age: >=50 (ref.:<30)",
  #   "Education (ref. Hauptschule): Mittlere Reife",
  #   "Education (ref. Hauptschule): Fachabitur",
  #   "Education (ref. Hauptschule): Abitur",
  #   "Privacy concern",
  #   "Account Facebook: No, but before (ref.: Never)",
  #   "Account Facebook: Yes (ref.: Never)",
  #   "Account Google: No, but before (ref.: Never)",
  #   "Account Google: Yes (ref.: Never)",
  #   "Device: Smartphone",
  #   "Device: Cell phone (no smartphone)",
  #   "Device: Desktop/Laptop",
  #   "Device: Tablet",
  #   "Device: eReader",
  #   "Generalized trust"
  # ),
  out = "./tableA5-digital-literacy.html"
)
```


```{r tableA6-digital-literacy, echo=TRUE, results="asis"}
# Models that use number.devices rather the device dummies as control


# Lm models for comparison of intercepts
outcomes <- c("trust.google.diff", "trust.facebook.diff", "trust.fedoffstats.diff", "trust.researchers.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did)
         )

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = data.did))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel)."),
  header = FALSE,
  no.space = TRUE,
  # covariate.labels = c(
  #   "GDPR Awareness (0 = No Change, 1 = Positive Change)",
  #   "Female",
  #   "Age: 30-49 (ref.:<30)",
  #   "Age: >=50 (ref.:<30)",
  #   "Education (ref. Hauptschule): Mittlere Reife",
  #   "Education (ref. Hauptschule): Fachabitur",
  #   "Education (ref. Hauptschule): Abitur",
  #   "Privacy concern",
  #   "Account Facebook: No, but before (ref.: Never)",
  #   "Account Facebook: Yes (ref.: Never)",
  #   "Account Google: No, but before (ref.: Never)",
  #   "Account Google: Yes (ref.: Never)",
  #   "Device: Smartphone",
  #   "Device: Cell phone (no smartphone)",
  #   "Device: Desktop/Laptop",
  #   "Device: Tablet",
  #   "Device: eReader",
  #   "Generalized trust"),
  font.size = "tiny",
  out = "./tableA6-digital-literacy.html"
)
```


## Stuff not in the paper


## Stats: Change/trend in treatment/control group for trust outcomes

Calculate the mean change/trend for respondents in the control group (0 -> 0) and respondents in the treatment group (0 -> 1).

The table below displays changes both in treated and control units. Important, this is the raw difference in the average change between the two groups (no controls etc.). The trend difference, e.g. for trust.facebook between treatment/control should equal the naive estimate of the first differences model (table2-fd.html). It does not and that's strange... (check)


```{r trends-changes-in-treatment-control-group}
table(data.w1w2$gdpr.know.num.diff)
table <- data.w1w2 %>%
  group_by(gdpr.know.num.diff) %>%
  select(
    trust.google.diff,
    trust.facebook.diff,
    trust.researchers.diff,
    trust.fedoffstats.diff
  ) %>%
  summarise_all(funs(round(mean(., na.rm = TRUE), 4), n = n())) %>%
  na.omit() %>%
  select(1, 6, 2:5) %>% rename("n_wo_NA" = "trust.google.diff_n",
                               "group" = "gdpr.know.num.diff")

  table$group <- recode(table$group, "0" = "control (0)", "1" = "treatment (1)")

difference <- table[2, 2:6] - table[1, 2:6]
difference <- c("difference", as.numeric(difference[1, ]))
table <- rbind(table, difference)
table <- kable(table,
  row.names = FALSE,
  caption = "Change (Wave 1 to Wave 2) in treatment and control groups (0->0 vs. 0->1)", format = "html", booktabs = T
) %>%
  kable_styling(full_width = T, font_size = 12)

save_kable(table, "Table - Change in treatment and control - Manual.html", self_contained = TRUE)
```




## Low trust subsets


```{r generate-low-trust-variable, eval=FALSE, include=FALSE, results="asis"}
# Create variable that contains row max. across trust vars
  data.did <- data.did %>%
    mutate(trust.max = pmax(
      trust.google,
      trust.facebook,
      trust.fedoffstats,
      trust.researchers
    ))

# Create var this is 1 for low trusters (<=5 max value across scales) and 0 otherwise
  data.did$initialtrust <- NA
  data.did$initialtrust[data.did$trust.max <= 5] <- 1
  data.did$initialtrust[data.did$trust.max > 5] <- 0
```

Generate subsets of the dataset.

```{r generate-data-subsets, eval=FALSE, include=FALSE}
# Devices
table(data.did$number.devices)
data.did.number.devices.low <- data.did %>% filter(number.devices<=2)
data.did.number.devices.high <- data.did %>% filter(number.devices>=4)

# Accounts
table(data.did$number.accounts)
data.did.number.accounts.low <- data.did %>% filter(number.accounts==0)
data.did.number.accounts.high <- data.did %>% filter(number.accounts>=3)

# Abitur
table(data.did$abitur)
data.did.abitur.no <- data.did %>% filter(abitur==0)
data.did.abitur.yes <- data.did %>% filter(abitur==1)

# Privacy worry
table(data.did$privacy.worry.numeric)
data.did.privacy.worry.low <- data.did %>% filter(privacy.worry.numeric<=1)
data.did.privacy.worry.high <- data.did %>% filter(privacy.worry.numeric>=2)

# Trust (at Wave 1)
table(data.did$initialtrust)
data.did.initialtrust.low <- data.did %>% filter(initialtrust==1)
data.did.initialtrust.high <- data.did %>% filter(initialtrust==0)
```  

Estimate models looping over datasets.

```{r tableA6-data-subsets, eval=FALSE, include=FALSE, results="asis"}



subsets <- ls()[grepl("data\\.did\\.", ls())]


for(y in subsets){
  
# Exclude controls that conflict with subsetting variables
  if(str_detect(y, "abitur")){
    controls <- controls[!str_detect(controls, "educ")]
  }
  if(str_detect(y, "privacy.worry")){
    controls <- controls[!str_detect(controls, "privacy.worry")]
  }  


# Lm models for comparison of intercepts
outcomes <- c("trust.google.diff", "trust.facebook.diff", "trust.fedoffstats.diff", "trust.researchers.diff")
treatment <- "gdpr.know.num.diff"


model.list <- NULL
z <- 1
for (i in outcomes) {
  
  # Construct models: Bivariate ####
  formula <- paste(i, treatment, sep = " ~ ")
  model.object.name <- paste("fit.lm.", i, ".nocontrols", sep = "")
  
  # Estimate bivariate PLM FD models
  assign(model.object.name, 
         lm(as.formula(formula),
               data = get(y)))

  # Store model results
  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <- model.object.name
  
  # Update counter
  z <- z + 1

  
  # Construct models: With controls ####
  formula <- paste(i, paste(c(treatment, controls), collapse = " + "), sep = " ~ ") # controls would need to be diffed as well
  model.object.name <- paste("fit.lm.", i, ".withcontrols", sep = "")
  
  # Estimate LMs
  assign(model.object.name, 
         lm(as.formula(formula),
               data = get(y)))

  model.list[[z]] <- get(ls()[str_detect(ls(), model.object.name)])
  names(model.list)[z] <-model.object.name

  z <- z + 1
}


# Automatize generation of outcome labels
outcomes <- str_replace_all(str_extract_all(names(model.list), "\\.[a-z_]*\\.[a-z_]*\\.[a-z_]*$"), "\\.withcontrols|\\.nocontrols", "")
outcomes <- gsub("\\.", " ", outcomes)
outcomes <- gsub("^\\s", "", outcomes)
outcomes <- gsub("(^|[[:space:]])([[:alpha:]])", "\\1\\U\\2", outcomes, perl = TRUE)
outcomes <- unique(outcomes)

stargazer(model.list,
  type = "html",
  title = "",
  omit.stat = c("LL", "ser", "f", "adj.rsq"),
  t.auto = T, p.auto = T,
  dep.var.caption = "Trust in organizations",
  dep.var.labels.include = FALSE,
  ci = FALSE,
  digits = 2,
  ci.level = 0.95,
  single.row = FALSE,
  label = "tab:fe-within",
  table.placement = "H",
  column.sep.width = "-7pt",
  align = TRUE,
  column.labels = c(
    "Google",
    "Facebook",
    "Federal Stat. Office",
    "Univ. Researchers"
  ),
  column.separate = c(2, 2, 2, 2, 2),
  model.names = FALSE,
  model.numbers = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  notes = c("Data: Respondents to both Wave 1 and Wave 2 (balanced panel).",
            paste("Respondents of data subset ", gsub("data.did.", "",y), sep = "")),
  header = FALSE,
  no.space = TRUE,
  # covariate.labels = c(
  #   "GDPR Awareness (0 = No Change, 1 = Positive Change)",
  #   "Female",
  #   "Age: 30-49 (ref.:<30)",
  #   "Age: >=50 (ref.:<30)",
  #   "Education (ref. Hauptschule): Mittlere Reife",
  #   "Education (ref. Hauptschule): Fachabitur",
  #   "Education (ref. Hauptschule): Abitur",
  #   "Privacy concern",
  #   "Account Facebook: No, but before (ref.: Never)",
  #   "Account Facebook: Yes (ref.: Never)",
  #   "Account Google: No, but before (ref.: Never)",
  #   "Account Google: Yes (ref.: Never)",
  #   "Device: Smartphone",
  #   "Device: Cell phone (no smartphone)",
  #   "Device: Desktop/Laptop",
  #   "Device: Tablet",
  #   "Device: eReader"),
  font.size = "tiny",
  out = paste("tableA8-subset-", gsub("\\.", "-", gsub("data.did.", "",y)), ".html", sep="")
)
}
```
